﻿using System.Diagnostics;
using Helper;

namespace CSharpBasic;

public class FolderOperations
{
    public static void Main()
    {
        new FolderOperations().FolderOperation();
    }
    public void FolderOperation()
    {
        string startFolder = @"D:\Users\Administrator\Documents\ICChat Files\menghou\images";
        
        // 检查是否存在文件夹路径
        bool _exists = Directory.Exists(startFolder);
        if (!_exists)
        {
            HelperTools.Console_WriteLine_ChangeColor(ConsoleColor.Red, "the path is not exist: {0}", startFolder);
            return;
        }
        
        // 根据路径生成文件夹对象
        System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(startFolder);
        
        Stopwatch s1 = Stopwatch.StartNew();
        // 此方法假定应用程序对指定路径下的所有文件夹具有发现权限
        IEnumerable<System.IO.FileInfo> fileList = dir.GetFiles("*.*", System.IO.SearchOption.AllDirectories);
        int cnt = 0;
        foreach (var VARIABLE in fileList)
        {
            cnt++;
        }

        HelperTools.Console_WriteLine_ChangeColor(ConsoleColor.Red, "文件数量：" + cnt);
        s1.Stop();

        Console.WriteLine(((double)(s1.Elapsed.Milliseconds)).ToString("0. ms"));
    }
}